<!DOCTYPE html>
<html>
<head>
    <title>我的页面</title>
    <style>
        /* Reset default browser styles */
        html, body {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            overflow-x: hidden; /* Prevent horizontal scrollbar */
        }

        body {
            font-family: sans-serif;
            background-color: #f8f8f8;
            color: #333;
            display: flex;
            flex-direction: column;
        }
        .container {
            flex: 1; /* 让内容区域填充剩余空间 */
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 100%; /* 确保容器宽度为100% */
            padding: 0; /* 移除容器内边距 */
            box-sizing: border-box; /* 确保padding和border不会增加总宽度 */
            overflow-y: auto; /* 允许内容滚动 */
            padding-bottom: 120px; /* 为tabbar留出空间，与tabbar高度一致 */
        }

        /* Tabbar styles */
        .tabbar {
            display: flex;
            justify-content: space-around;
            align-items: center;
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 120px; /* Adjusted tabbar height */
            background-color: #fff;
            border-top: 1px solid #eee;
            box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
            z-index: 1000;
        }

        .tabbar-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            flex: 1;
            color: #666;
            text-decoration: none;
            font-size: 14px; /* Adjusted font size */
            padding: 5px 0;
        }

        .tabbar-item.active {
            color: #007bff; /* Active color */
        }

        .tabbar-item img {
            width: 40px; /* Adjusted icon size */
            height: 40px; /* Adjusted icon size */
            margin-bottom: 2px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="content">
            <h1>我的页面内容</h1>
            <p>这里是我的页面的具体内容。</p>
            <p id="login-status">您尚未登录。</p>
            <button id="login-button" onclick="redirectToWeChatOAuth()">微信登录</button>
        </div>
    </div>

    <div class="tabbar">
        <a href="/rzwl/static/index.html" class="tabbar-item">
            <img src="/rzwl/static/images/tab_home.png" alt="首页">
            <span>首页</span>
        </a>
        <a href="/rzwl/static/enroll.html" class="tabbar-item">
            <img src="/rzwl/static/images/tab_enroll.png" alt="报名">
            <span>报名</span>
        </a>
        <a href="/rzwl/static/pay.html" class="tabbar-item">
            <img src="/rzwl/static/images/tab_pay.png" alt="支付">
            <span>支付</span>
        </a>
        <a href="/rzwl/static/me.html" class="tabbar-item active">
            <img src="/rzwl/static/images/tab_me_active.png" alt="我的">
            <span>我的</span>
        </a>
    </div>

    <script>
        async function checkLoginStatus() {
            const response = await fetch('/rzwl/check_login_status');
            const data = await response.json();
            const loginStatusElement = document.getElementById('login-status');
            const loginButton = document.getElementById('login-button');

            if (data.logged_in) {
                if (loginStatusElement) {
                    loginStatusElement.textContent = `您已登录，OpenID: ${data.openid}`;
                }
                if (loginButton) {
                    loginButton.style.display = 'none'; // 隐藏登录按钮
                }
            } else {
                if (loginStatusElement) {
                    loginStatusElement.textContent = `您尚未登录。`;
                }
                if (loginButton) {
                    loginButton.style.display = 'block'; // 显示登录按钮
                }
            }
        }

        async function redirectToWeChatOAuth() {
            const appidResponse = await fetch('/rzwl/get_wechat_appid');
            const appidData = await appidResponse.json();
            const appid = appidData.appid;

            const currentPath = window.location.pathname + window.location.search;
            // 获取不带端口的域名或IP
            const hostname = window.location.hostname;
            const redirectUri = encodeURIComponent(`${window.location.protocol}//${hostname}/rzwl/wechat_oauth_callback`);
            const wechatOAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=${encodeURIComponent(currentPath)}#wechat_redirect`;
            window.location.href = wechatOAuthUrl;
        }

        // 页面加载时检查登录状态
        checkLoginStatus();
    </script>
</body>
</html>
